﻿using dbasyn.model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace dbasyn
{
    public class Mysql
    {

       //var  App.Configuration["ConnectionStrings:mysql"];
      static   SqlSugarClient Db = new SqlSugarClient(new ConnectionConfig()
        {
            ConnectionString = "Data Source=rm-2zen435212pw4dqo2.mysql.rds.aliyuncs.com;Database=lxb;User ID=lexunbao;Password=lexunbao111!!!;pooling=true;port=3306;sslmode=none;CharSet=utf8;",
            DbType = SqlSugar.DbType.MySql,
            IsAutoCloseConnection = true
        },
          db => {
              //5.1.3.24统一了语法和SqlSugarScope一样，老版本AOP可以写外面

              db.Aop.OnLogExecuting = (sql, pars) =>
              {
               //   Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响

                  //5.0.8.2 获取无参数化SQL 对性能有影响，特别大的SQL参数多的，调试使用
                  //UtilMethods.GetSqlString(DbType.SqlServer,sql,pars)
              };

                   //注意多租户 有几个设置几个
                   //db.GetConnection(i).Aop

          });

        public static lxb_user getUserByrfid(String rfid)
        {
            return Db.Queryable<lxb_user>().Where(u=>u.rfid.Equals(rfid)).First();
        }
        public static lxb_user getUser(int uid)
        {
            return Db.Queryable<lxb_user>().Where(u => u.user_id.Equals(uid)).First();
        }
        public static lxb_weixin_dev getDev(String id)
        {
            return Db.Queryable<lxb_weixin_dev>().Where(u => u.id.Equals(id)).First();
        }

        public static lxb_weixin_dev_tag getTag(int id)
        {
            return Db.Queryable<lxb_weixin_dev_tag>().Where(u => u.id.Equals(id)).First();
        }
    }
}
